package com.zhku.shop.controller;


import com.zhku.base.model.PageParams;
import com.zhku.base.model.PageResult;
import com.zhku.base.model.RestResponse;
import com.zhku.shop.model.dto.QueryShopParamsDto;
import com.zhku.shop.model.dto.ShopDto;
import com.zhku.shop.model.po.TtShop;
import com.zhku.shop.service.TtShopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api(value = "店铺相关接口",tags = "店铺相关接口")
@RestController
public class TtShopController {

    @Autowired
    private TtShopService ttShopService;

    @ApiOperation("新增店铺接口")
    @PostMapping("/createShop")
    public RestResponse<TtShop> createShop(@RequestBody ShopDto shopDto){
        TtShop ttShop = ttShopService.createShop(shopDto);
        return RestResponse.success(ttShop);
    }

    @ApiOperation("删除店铺接口")
    @PostMapping("/deleteShop/{id}")
    public RestResponse deleteShop(@PathVariable("id") String id){
        ttShopService.deleteShop(id);
        return RestResponse.success();
    }

    @ApiOperation("修改店铺接口")
    @PostMapping("/updateShop")
    public RestResponse<TtShop> updateShop(@RequestBody TtShop ttShop){
        TtShop ttShopNew = ttShopService.updateShop(ttShop);
        return RestResponse.success(ttShopNew);
    }

    @ApiOperation("查询店铺接口")
    @GetMapping("/shopInfo/{id}")
    public RestResponse<TtShop> getShop(@PathVariable("id") String id){
        TtShop ttShop = ttShopService.getShop(id);
        return RestResponse.success(ttShop);
    }

    @ApiOperation("分页查询所有店铺")
    @PostMapping("/shopInfo/list")
    public PageResult<TtShop> list(PageParams pageParams, @RequestBody(required = false) QueryShopParamsDto queryShopParamsDto){
        PageResult<TtShop> addressPageResult = ttShopService.queryShopList(pageParams,queryShopParamsDto);
        return addressPageResult;
    }

    @ApiOperation("根据店铺名称查询当前店铺是否存在")
    @PostMapping("/shopByName")
    public RestResponse<TtShop> shopByName(@RequestBody String name){
        TtShop ttShop = ttShopService.shopByName(name);
        return RestResponse.success(ttShop);
    }

}
